/*
This file is part of web3.js.

web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with web3.js.  If not, see <http://www.gnu.org/licenses/>.
*/
import { Bytes, TransactionInfo } from 'web3-types';
import { bytesToUint8Array, hexToBytes } from 'web3-utils';

import Web3 from '../../../src';
import { getSystemE2ETestProvider } from '../e2e_utils';
import {
	closeOpenConnection,
	getSystemTestBackend,
} from '../../shared_fixtures/system_tests_utils';
import { toAllVariants } from '../../shared_fixtures/utils';

describe(`${getSystemTestBackend()} tests - getTransaction`, () => {
	const provider = getSystemE2ETestProvider();

	let web3: Web3;

	beforeAll(() => {
		web3 = new Web3(provider);
	});

	afterAll(async () => {
		await closeOpenConnection(web3);
	});

	it.each(
		toAllVariants<{
			transactionHash: Bytes;
		}>({
			transactionHash: [
				'0xcf811d80757452f648f74bea7cdee088c5c2addafd8d049f644fc8cafee7a50d',
				bytesToUint8Array(
					hexToBytes(
						'0xcf811d80757452f648f74bea7cdee088c5c2addafd8d049f644fc8cafee7a50d',
					),
				),
				new Uint8Array(
					hexToBytes(
						'0xcf811d80757452f648f74bea7cdee088c5c2addafd8d049f644fc8cafee7a50d',
					),
				),
			],
		}),
	)('getTransaction', async ({ transactionHash }) => {
		const result = await web3.eth.getTransaction(transactionHash);

		expect(result).toMatchObject<TransactionInfo>({
			blockHash: '0xbdec00d52c5b4e1c00e0821fdaa492c0330ae06504d27a7e9f2e3e014957e96d',
			blockNumber: BigInt(6790201),
			from: '0xaa88878d91bc1a7b7f71c592349efc44b5f3b77d',
			gas: BigInt(73225),
			gasPrice: BigInt(344362611607),
			hash: '0xcf811d80757452f648f74bea7cdee088c5c2addafd8d049f644fc8cafee7a50d',
			input: '0x95b335c84d053fdf52290285953409c8d9abdacc0000000066fb1966037903179f000000000000000000000000000000000000000000000000000000000000000007a13b0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000423078653030353565656530616135303532306162306162343132663535303666396635656664653663633561326565633231643031613063326266346638396261310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000299c007f9c00000000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000001a3078313a3a6170746f735f636f696e3a3a4170746f73436f696e000000000000',
			nonce: BigInt(2),
			to: '0xd600d94d0812f7edfa47d0cf02a767b1dd14a01b',
			transactionIndex: BigInt(1),
			value: BigInt(732000000000000),
			type: BigInt(0),
			chainId: BigInt(11155111),
			v: BigInt(22310257),
			r: '0x1cf2c321ee1a4331dee4f9243fc1a73aa23b49929d0f5e475b27685c303fc4b1',
			s: '0x009d5ffea271ec91f967e2993ff83c2576c63e83604ca8934768ede951ed1c5a',
			data: '0x95b335c84d053fdf52290285953409c8d9abdacc0000000066fb1966037903179f000000000000000000000000000000000000000000000000000000000000000007a13b0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000423078653030353565656530616135303532306162306162343132663535303666396635656664653663633561326565633231643031613063326266346638396261310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000299c007f9c00000000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000001a3078313a3a6170746f735f636f696e3a3a4170746f73436f696e000000000000',
		});
	});
});
